<?php
namespace Depart\Controller;
use Think\Controller;

Class DwgController extends Controller{
	public function dwginfo(){
		$dwgs=D('dwg')->relation(True)->order('type,volume,wpressure')
		// ->fields('dwgcode','dwgname','spec',from_unixtime('date'),'dname')
		->select();
		$this->assign('dwgs',$dwgs);
		// dump($dwgs);die;
		$this->display();
	}
	public function add_dwg(){
		$data=I('post.');
		if($data){
			$data['date']=strtotime($data['date']);
			//dump($data);die;
	        $result=D('Dwg')->add($data);
	        if ($result) {
	            $this->success('添加成功',U('Depart/Dwg/dwginfo'));
	        }else{
	            $this->error('添加失败，可能图号有重复');
	        }
        }else{
        	$map['type']=D('type')->where('type="产品分类"')->select();
        	$map['users']=D('users')->where('id>90')->select();
        	// dump($map);die;
        	$this->assign('map',$map);
        	$this->display();
        }
	}
// 修改图纸信息
	public function edit_dwg(){
        $data=I('post.');
        $map=array(
            'id'=>$data['id']
            );
        // $result=D('Dwg ')->save($map,$data);
        $result=D('Dwg')->where($map)->save($data);
        if ($result) {
            $this->success('修改成功',U('Depart/Dwg/dwginfo'));
        }else{
            $this->error('修改失败');
        }
    }
// 删除图纸
    public function del_dwg(){
        $id=I('get.id');
        $map=array(
            'id'=>$id
            );
        $result=D('Dwg')->delete($map);
        if($result){
            $this->success('删除成功',U('Depart/Dwg/dwginfo'));
        }else{
            $this->error('删除失败');
        }

    }
}